package com.tyjc.unique.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;

import com.tyjc.unique.bean.SSQTrendChart;
import com.tyjc.lottery.R;
import com.fyzk.utils.LogUtil;

import java.util.ArrayList;


public class OnDrawLeft extends ZouShiOnDraw{
	
	private Paint bgPaint;
	private Paint linePaint;
	private Paint textPaint;
	
	private int color_bg_h;//灰
	private int color_bg_w;//白
	private int color_line;
	private int color_text1;
	
	private int zi_cxcs;
	private int zi_pjlc;
	private int zi_zdyl;
	private int zi_zdlc;
	public ArrayList<SSQTrendChart> arrayChartItems = new ArrayList<SSQTrendChart>();

	public OnDrawLeft(Context context) {
		super(context);
	}
	
	public OnDrawLeft(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	public OnDrawLeft(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}
	
	@Override
	protected void init(Context context) {
		super.init(context);
		color_bg_h = context.getResources().getColor(R.color.bgh);
		color_bg_w = context.getResources().getColor(R.color.bgb);
		color_line = context.getResources().getColor(R.color.shu_line);
		color_text1 = context.getResources().getColor(R.color.zi_c);
		
		zi_cxcs = context.getResources().getColor(R.color.cxcs);
		zi_pjlc = context.getResources().getColor(R.color.pjlc);
		zi_zdlc = context.getResources().getColor(R.color.zdlc);
		zi_zdyl = context.getResources().getColor(R.color.zdyl);
		
		bgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		bgPaint.setColor(color_bg_w);
		
		linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		linePaint.setColor(color_line);
		linePaint.setStrokeWidth(1);
		
		textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		textPaint.setColor(color_text1);
		textPaint.setTextSize(16 * screen_density);
		
//		totalWidth = (float) (unitLength * 2.5);
//		totalHeight = unitLength * issue_count;
//		setMeasuredDimension((int)totalWidth, (int)totalHeight);
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		canvas.drawColor(Color.WHITE);
		for (int i = 1; i < (row+1); i++) {
			String text = "";
			try {
				text = arrayChartItems.get(i-1).getPhase();
				text = text.substring(2, text.length()) + "期";
			} catch (Exception e) {
				LogUtil.e(e.getMessage());
			}
//			if (i<100) {
//				if (i<10) {
//					text = "00"+i+"期";
//				}else{
//					text = "0"+i+"期";
//				}
//			}else{
//				text = i+"期";
//			}
			int x0 = 0;
			int x1 = (int)totalWidth;
			int y0 = (int)(unitLength*(i-1));
			int y1 = (int)(unitLength*i);
			Rect rect = new Rect(x0, y0, x1, y1);
			
			//绘制背景颜色
			//绘制背景颜色
			if (i % 2 == 0) {
				bgPaint.setColor(color_bg_h);
			}else {
				bgPaint.setColor(color_bg_w);
			}
			canvas.drawRect(rect, bgPaint);
			
			//绘制线条
			
			if (isShowTongJi && i== row - 3) {
				linePaint.setStrokeWidth(2);
				canvas.drawLine(0, y0, totalWidth, y0, linePaint);
			}
			
			//绘制文字
			if (isShowTongJi) {
				if (i == row-3) {//出现次数
					textPaint.setColor(zi_cxcs);
					text = "出现次数";
				}else if (i== row-2) {//平均遗漏
					textPaint.setColor(zi_pjlc);
					text = "平均遗漏";
				}else if (i== row-1) {//最大遗漏
					textPaint.setColor(zi_zdyl);
					text = "最大遗漏";
				}else if (i== row) {//最大连出
					textPaint.setColor(zi_zdlc);
					text = "最大连出";
				}else{
					textPaint.setColor(color_text1);
				}
			}else{
				textPaint.setColor(color_text1);
			}
			
			drawText(canvas, textPaint, text, rect);
		}
	}
	
	@Override
	protected void setTotalWH() {
		totalWidth = (float) (unitLength * 2.5);
		totalHeight = unitLength * row;
		
		setMeasuredDimension((int)totalWidth, (int)totalHeight);
		this.invalidate();
	}
	
}
